package com.lrs.java.j2se_base.baseSyntax;
public class Fab {
	public static void main(String[] args) {
		System.out.println(f(9));
		
		System.out.println(recursive(9));
	}
	
	public static long f(int index) {
		if(index < 1) {
			System.out.println("invalid parameter!");
			return -1;
		}
		
		if(index == 1 || index == 2) {
			return 1;
		}
		
		long f1 = 1L;
		long f2 = 1L;
		long f = 0;
		
		for(int i=0; i<index-2; i++) {
			f = f1 + f2;
			f1 = f2;
			f2 = f;
		}
		
		return f;
	}
	
	public static int recursive(int num) {
		
		if(num < 0) {
			System.out.println("incorrect number input");
			return 0;
		} else if(num == 1 || num == 2) {
			return 1;
		} else {
			return recursive(num - 1) + recursive(num - 2);
		}
	}
}